package zuoye5;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class List { // 1. 改进类名
    public static void main(String[] args) {
        ArrayList<Map<String, Object>> userList = new ArrayList<>(); // 3. 提高代码可读性

        try {
            Map<String, Object> user1 = new HashMap<>();
            user1.put("name", "联通");
            user1.put("id", 10010);
            user1.put("age", 18);
            userList.add(user1); // 2. 增加异常处理

            Map<String, Object> user2 = new HashMap<>();
            user2.put("name", "移动");
            user2.put("id", 10086);
            user2.put("age", 19);
            userList.add(user2);
        } catch (Exception e) {
            System.err.println("添加用户数据时发生错误: " + e.getMessage());
        }

        for (Map<String, Object> user : userList) { // 3. 提高代码可读性
            System.out.println(formatUser(user)); // 4. 增强输出信息的可读性
        }
    }

    private static String formatUser(Map<String, Object> user) {
        return "姓名: " + user.get("name") + ", ID: " + user.get("id") + ", 年龄: " + user.get("age");
    }
}
